import { FormSchema, BasicColumn } from '/@/components/Table';
import data from './dataType.json';
export const searchFormSchema: FormSchema[] = [
  {
    field: 'source',
    label: '规则动作类型',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [{ label: '保存到Kafka', value: 'SEND_KAFKA' }],
    },
  },
];

const isKafka = (value) => value === 'SEND_KAFKA' || value === 'SAVE_PULSAR' || value === 'SEND_ROCKET_MQ';
const isSql = (value) =>
  value === 'SAVE_MYSQL' ||
  value === 'SAVE_CLICKHOUSE' ||
  value === 'SAVE_ORACLE' ||
  value === 'SAVE_TDENGINE' ||
  value === 'SAVE_POSTGRESQL' ||
  value === 'OFFLINE_POSTGRESQL' ||
  value === 'SAVE_TDENGINE' ||
  value === 'OFFLINE_MYSQL';
const isWebHook = (value) => value === 'SEND_WEBHOOK';
const isMQtt = (value) => value === 'SEND_MQTT';
const isRocketMQ = (value) => value === 'SEND_ROCKET_MQ';
const isRabbitMQ = (value) => value === 'SEND_RABBIT_MQ';
const isRedis = (value) => value === 'SEND_REDIS';
const isPostgresql = (value) => value === 'OFFLINE_POSTGRESQL' || value === 'OFFLINE_MYSQL';
const isLineRedis = (value) => value === 'OFFLINE_REDIS';

export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'ruleName',
    label: '规则名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'divider-linked',
    label: '模拟测试',
    component: 'Divider',
    componentProps: {
      plain: false,
    },
  },
  {
    field: 'ruleDataTypes',
    label: '规则数据类型',
    component: 'Select',
    componentProps: {
      mode: 'multiple',
      options: data.dataType,
    },
    required: true,
  },
  {
    field: 'sql',
    label: 'sql',
    component: 'JCodeEditor',
    componentProps: {
      language: 'sql',
      height: '180px',
      fullScreen: false,
    },
  },
  {
    field: 'sqlFields',
    label: '可选参数',
    component: 'Input',
    slot: 'sqlField',
  },
  {
    field: 'sqlds',
    label: '',
    component: 'Input',
    slot: 'test',
  },
  {
    field: 'divider-linked',
    label: '筛选数据',
    component: 'Divider',
    componentProps: {
      plain: false,
    },
  },
  {
    field: 'ruleActionType',
    label: '规则动作类型',
    component: 'Select',
    componentProps: {
      options: data.ruleAction,
    },
    required: true,
  },
  {
    field: 'ruleAction',
    label: '数据源',
    component: 'Input',
    slot: 'datasource',
    required: true,
    ifShow: ({ values }) => values.ruleActionType,
  },
  {
    field: 'topic',
    label: '主题',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isKafka(values.ruleActionType) || isMQtt(values.ruleActionType),
  },
  {
    field: 'key',
    label: 'key',
    component: 'Input',
    ifShow: ({ values }) => isKafka(values.ruleActionType),
  },
  {
    field: 'sqltemplate',
    label: '保存SQL模板',
    component: 'JCodeEditor',
    componentProps: {
      height: '180px',
      fullScreen: false,
    },
    ifShow: ({ values }) => isSql(values.ruleActionType),
  },
  {
    field: 'template',
    label: '请求模板',
    component: 'Input',
    ifShow: ({ values }) => isWebHook(values.ruleActionType),
  },
  {
    field: 'qos',
    label: 'Qos',
    component: 'Input',
    ifShow: ({ values }) => isMQtt(values.ruleActionType),
  },
  {
    field: 'tag',
    label: 'tag',
    component: 'Input',
    ifShow: ({ values }) => isRocketMQ(values.ruleActionType),
  },
  {
    field: 'queue',
    label: '队列',
    component: 'Input',
    ifShow: ({ values }) => isRabbitMQ(values.ruleActionType),
  },
  {
    field: 'exchange',
    label: '交换机',
    component: 'Input',
    componentProps: {
      placeholder: '请输入交换机 (如不填则使用默认交换机)',
    },
    ifShow: ({ values }) => isRabbitMQ(values.ruleActionType),
  },
  {
    field: 'redis',
    label: 'Redis命令',
    component: 'Input',
    ifShow: ({ values }) => isRedis(values.ruleActionType),
  },
  {
    field: 'searchsql',
    label: '查询SQL模板',
    component: 'JCodeEditor',
    componentProps: {
      height: '180px',
      fullScreen: false,
    },
    ifShow: ({ values }) => isPostgresql(values.ruleActionType),
  },
  {
    field: 'deletesql',
    label: '删除SQL模板',
    component: 'JCodeEditor',
    componentProps: {
      height: '180px',
      fullScreen: false,
    },
    ifShow: ({ values }) => isPostgresql(values.ruleActionType),
  },
  {
    field: 'expiretime',
    label: 'Redis过期时间(天)',
    component: 'Input',
    ifShow: ({ values }) => isLineRedis(values.ruleActionType),
  },
  {
    field: 'desc',
    label: '规则描述',
    component: 'Input',
  },
];

export const formSchema1: FormSchema[] = [
  {
    field: 'type',
    label: 'SQL调试',
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '调试参数', value: '0' },
        { label: '调试结果', value: '1' },
      ],
    },
  },
  {
    field: 'ruleDataTypes',
    label: '规则数据类型',
    component: 'Select',
    componentProps: {
      mode: 'multiple',
      options: data.dataType,
    },
  },
  {
    label: '测试sql',
    field: 'param',
    component: 'JCodeEditor',
    componentProps: {
      height: '180px',
      fullScreen: false,
    },
  },
];

export const columns1: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'sourceKey',
  },
  {
    title: '数据源名称',
    dataIndex: 'sourceName',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
  },
];
